/**
 * 
 */
package com.point.business.database.util;

import java.text.MessageFormat;
import java.util.List;

import com.point.business.database.managers.ScheduleManager;
import com.point.business.database.managers.UsersManager;
import com.point.business.database.model.InformationND;
import com.point.business.database.model.InformationNO;
import com.point.business.database.model.InformationSL;
import com.point.business.database.model.Schedule;
import com.point.business.database.model.User;
import com.point.business.util.Settings;

/**
 * @author Ilija Trajkoski
 * 
 */
public class EmailMessageComposer {

	public String composeAndSendMessageSL(List<InformationSL> list,
			Schedule schedule) {
		User user = UsersManager.getInstance()
				.getUserById(schedule.getUserId());
		String result = Settings.getValue("mail.content.header");
		for (InformationSL informationSL : list) {
			result += MessageFormat.format(
					Settings.getValue("mail.content.sl"),
					informationSL.getEmbs(), informationSL.getTitle(),
					informationSL.getProcedure(), informationSL.getUuid(),
					informationSL.getAnounceDate(),
					informationSL.getAnounceBy(),
					informationSL.getDesctription());
		}
		result += Settings.getValue("mail.content.footer");
		String title = Settings.getValue("mail.title");
		EmailSender.getInstance().sendEmail(user.getEmail(), title, result);
		ScheduleManager.getInstance().setSendingTime(schedule.getId());
		return result;
	}

	public String composeAndSendMessageND(List<InformationND> list,
			Schedule schedule) {
		User user = UsersManager.getInstance()
				.getUserById(schedule.getUserId());
		String result = Settings.getValue("mail.content.header");
		for (InformationND informationND : list) {
			result += MessageFormat.format(
					Settings.getValue("mail.content.nd"),
					informationND.getFullName(), informationND.getAddress(),
					informationND.getCity(), informationND.getType(),
					informationND.getDocumentNumber(),
					informationND.getAnnouncmentIssueDate(),
					informationND.getAnnouncmentIssueNumber(),
					informationND.getAnnouncmentIssueDate(),
					informationND.getDocumentName());
		}

		result += Settings.getValue("mail.content.footer");
		String title = Settings.getValue("mail.title");
		EmailSender.getInstance().sendEmail(user.getEmail(), title, result);
		ScheduleManager.getInstance().setSendingTime(schedule.getId());
		return result;
	}

	public String composeAndSendMessageNO(List<InformationNO> list,
			Schedule schedule) {
		return "Test message NO Results appeared";
	}
}
